BIOF309 Introduction to Python

R. Burke Squires

Computational Biologist

NIAID Bioinformatics and Computational Biosciences Branch (BCBB)

Python Experience

  • Programming in python for 8 - 10 years
  • My main language for bioinformatics development

Teaching Experience

  • Oversee training for the BCBB
  • Teach Introduction to Python Programming through CIT on NIH Campus
  • I have been teaching at FAES for last 2 years
  • Also taught Data Science Courses for NIEHS in RTP, North Carolina

What are we going to cover today?

  • Intro survey
  • Syllabus overview
  • An introduction to computational thinking
  • What can you do with python
  • Why python?
  • Software installation
  • Jupyter notebook

An introduction to computational thinking

What does it mean to think computationally?

Automate the Boring Stuff

  • Moving and renaming thousands of files and sorting them into folders
  • Filling out online forms, no typing required
  • Downloading files or copy text from a website whenever it updates
  • Having your computer text you custom notifications
  • Updating or formatting Excel spreadsheets
  • Checking your email and sending out prewritten responses

Why python?

  • Python is easy to learn
  • Python is powerful
  • There is one obvious way to do something
  • Packages
    • There are almost 90,000 packages of software aready written
    • Scientific python stack packages
  • Large standard library of built-in functions; batteries included
  • Python is easy to read
  • Can easily handle strings

Why python, continued...

  • Scales well
  • Python is fast
  • Python is object oriented by default
  • Python is the default teaching language at many / most universities
  • Indentation!
  • Killer apps - Django, pandas, scikit-learn
  • Free learning
  • Rapid development cycle

How does python differe from other scripting languages

  • Implementation
  • Iterator - built-in
  • List comprehensions
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

What can you do with python

https://www.youtube.com/watch?v=-67hh86N42Q

Examples

  • Automate the boring stuff examples
  • Bioinformatics pipelines
  • Scrape data from a webpage
  • Run machine learning algorithms on data
  • Make games
  • Build websites
  • Analyze Excel data
  • Analyze image data
  • Program roborts or drones

Other examples:

Jupyter notebook introduction


In [5]:
## Our first program

print("Hello world")


Hello world

In [ ]:
## Add some interaction

name = input()
print("Hello " + name)

In [3]:
%%writefile hello_world_interactive.py

## Same as above but using Jupyter magic command '%%writefile' to save as a text file

name = input()
print("Hello " + name)


Writing hello_world_interactive.py

In [ ]: